package net.lookyou.boot.demo.service;

import net.lookyou.boot.demo.mapper.SysUserMapper;
import net.lookyou.boot.demo.entity.SysUser;
import net.lookyou.boot.demo.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class SysUserService {

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Autowired
    private PasswordEncoder passwordEncoder;

    public SysUser selectById(Integer id) {
        return userMapper.selectById(id);
    }

    public SysUser selectByName(String name) {
        return userMapper.selectByName(name);
    }

    public int registerUser(String name,String passWord){
        int userId = userMapper.addUser(name, passwordEncoder.encode(passWord));
        sysUserRoleMapper.registerAuthority(userId, 2);
        return 0;
    }
}